function animate() {
    let canvas = document.getElementById("_canvas");
    canvas.style.backgroundColor = '#f0f0f0';
    let ctx = canvas.getContext("2d");
    let engine = new Engine(ctx);
    let layer = new Layer(ctx);
    engine.addLayer(layer);

    let enemyFlyingAlt = [];
    let enemySwimming = [];
    let enemyWalking = [];

    let playerGrey_up = [];
    let playerGrey_walk = [];

    layer.preload = function (loader) {
        enemyFlyingAlt.push(loader.loadImage('animate/enemyFlyingAlt_1.png'));
        enemyFlyingAlt.push(loader.loadImage('animate/enemyFlyingAlt_2.png'));

        enemySwimming.push(loader.loadImage('animate/enemySwimming_1.png'));
        enemySwimming.push(loader.loadImage('animate/enemySwimming_2.png'));

        enemyWalking.push(loader.loadImage('animate/enemyWalking_1.png'));
        enemyWalking.push(loader.loadImage('animate/enemyWalking_2.png'));

        playerGrey_up.push(loader.loadImage('animate/playerGrey_up1.png'));
        playerGrey_up.push(loader.loadImage('animate/playerGrey_up2.png'));

        playerGrey_walk.push(loader.loadImage('animate/playerGrey_walk1.png'));
        playerGrey_walk.push(loader.loadImage('animate/playerGrey_walk2.png'));
    }

    layer.create = function () {
        let player = new SpriteObject();
        player.x = 400;
        player.y = 400;
        player.setImageSet(playerGrey_up, 10, 'up');
        player.setImageSet(playerGrey_walk, 10, 'walk');
        player.setDefaultFrame('walk');
        player.pause();
        let speed = 20;

        player.update = function (delta) {
            let xmove = 0;
            let ymove = 0;
            let move = speed * delta;
            if (Input.keybord_down_check('A')) {
                xmove -= move;
                this.flipX(-1);
            }
            if (Input.keybord_down_check('D')) {
                xmove += move;
                this.flipX(1);
            }
            if (Input.keybord_down_check('W')) {
                ymove -= move;
                this.flipY(1);
            }
            if (Input.keybord_down_check('S')) {
                ymove += move;
                this.flipY(-1);
            }
            if (xmove == 0 && ymove == 0) {
                this.pause();
                return;
            }
            if (xmove !== 0) {
                this.play('walk');
            }
            if (ymove !== 0) {
                this.play('up');
            }
            this.x += xmove;
            this.y += ymove;
        }
        layer.addObject(player);
    }
    engine.run();
    return engine;
}